import java.util.Stack;

public class StackMin {
    class MinStack {
        Stack<Integer> stack;
        Stack<Integer> minstack;
        public MinStack() {
            stack = new Stack<>();
            minstack = new Stack<>();
        }
        public void push(int val) {
            stack.push(val);
            if(minstack.empty()){
                minstack.push(val);
            }
            else{
                int tem = minstack.peek();
                if(val<=tem){
                    minstack.push(val);
                }
            }
        }

        public void pop() {
            int tem = stack.pop();
            if(!minstack.empty()){
                if(tem==minstack.peek()){
                    minstack.pop();
                }
            }
        }

        public int top() {
            return stack.peek();
        }

        public int getMin() {
            if(!minstack.empty()){
                return minstack.peek();
            }
            return -1;
        }
    }

}
